package com.timoon.component.panel.nav;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.panel.Panel;

import com.timoon.component.panel.jlayout.JLayouterPanel;

/**
 *<p></p>
 *<p></p>
 *<p>Copyright:Copyright(c)2013.4.1</p>
 *<p>Company:timoon</p>
 *@author 付乐天
 *@version 1.0 */
public class AbstractNavLink extends AjaxLink {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2778410333278834603L;
	private String layoutTargetId;
	private Panel targetPanel;
	
	private String code;
	
	public AbstractNavLink(String id,String layoutTargetId) {
		super(id);
		// TODO Auto-generated constructor stub
		this.layoutTargetId=layoutTargetId;
	}
	public AbstractNavLink(String id,String layoutTargetId,Panel targetPanel) {
		super(id);
		// TODO Auto-generated constructor stub
		this.layoutTargetId=layoutTargetId;
		this.targetPanel=targetPanel;
	}
	/**
	 * 获取目标panel有两种方法，第一种是从构造方法中注入，优先
	 * 第二种方法便是从此处获得
	 * */
	protected Panel getPanel(){
		return null;
	}
	protected String getLayoutTargetId2(){
		return null;
	}
	protected Panel getTargetPanel2(){
		return null;
	}

	/**
	 * 切换layout的面板
	 */
	@Override
	public void onClick(AjaxRequestTarget arg0) {
		// TODO Auto-generated method stub
		JLayouterPanel jLayouterPanel=(JLayouterPanel) this.getSession().getAttribute("jlayout-panel");
		jLayouterPanel.updatePanel(layoutTargetId, targetPanel==null?getPanel():targetPanel, arg0);
		
		if(this.getLayoutTargetId2()!=null){
			jLayouterPanel.updatePanel(this.getLayoutTargetId2(), this.getTargetPanel2(), arg0);
		}
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getCode() {
		return code;
	}
	

}
